package com.jingsheng.jingshengcity.mvp.ui.activity.account;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.UiUtils;
import com.jingsheng.jingshengcity.R;
import com.jingsheng.jingshengcity.di.component.DaggerLoginComponent;
import com.jingsheng.jingshengcity.di.module.LoginModule;
import com.jingsheng.jingshengcity.mvp.contract.LoginContract;
import com.jingsheng.jingshengcity.mvp.presenter.LoginPresenter;
import com.jingsheng.jingshengcity.mvp.ui.activity.MainActivity;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * Created by Administrator on 2017/5/4.
 */

public class LoginActivity extends BaseActivity<LoginPresenter> implements LoginContract.View, View.OnClickListener {

    @Nullable
    @BindView(R.id.tv_register)
    TextView mTvRegister;
    @Nullable
    @BindView(R.id.btn_login)
    Button mBtnLogin;

    @Override
    public void setupActivityComponent(AppComponent appComponent) {
        DaggerLoginComponent
                .builder()
                .appComponent(appComponent)
                .loginModule(new LoginModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView() {
        setTitle("登录");
        return R.layout.activity_login;
    }

    @Override
    public void initData() {
        initEvent();
    }

    private void initEvent() {
        mTvRegister.setOnClickListener(this);
        mBtnLogin.setOnClickListener(this);
    }

    @Override

    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        UiUtils.SnackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        UiUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public boolean useFragment() {
        return false;
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_register:
                toRegister();
                break;
            case R.id.btn_login:
                toMain();
                break;
        }
    }

    private void toMain() {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
    }

    private void toRegister() {
        //        Intent intent = new Intent(this, RegisterActivity.class);
        //        startActivity(intent);

        Intent intent = new Intent(this, VerificationCodeActivity.class);
        startActivity(intent);
    }
}